import { reactive } from 'vue'

export default function <T = Record<string, any>>(fields: FormFields<T>): T {
    const model = reactive({}) as T
    fields.forEach(item => {
        const { field, initValue, type } = item
        if (type === 'cRangePicker' && Array.isArray(field)) {
            model[field[0]] = initValue?.[0]
            model[field[1]] = initValue?.[1]
        } else if (type !== 'title' && field && typeof field === 'string') {
            model[field] = initValue
        }
    })
    return model
}
